package com.weiwei.diancan.view;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.weiwei.diancan.R;
import com.weiwei.diancan.adapter.IDBMemberPayStyleAdapter;


/**
 * Conpany:成都欧品在线电子商务有限公司技术服务中心
 * Auther:戚定泉
 * Date: 2016/5/9
 * Effect:加入会员支付对话框
 */
public class TbandDialog extends Dialog{
    private Activity context;
    private int which=-1;
    public TbandDialog(Activity context) {
        super(context, R.style.share_dialog);
        this.context=context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View view= LayoutInflater.from(context).inflate(R.layout.tband_dialog,null);
        ListView payLv= (ListView) view.findViewById(R.id.paystyle_lv);
        Button payBtn= (Button) view.findViewById(R.id.btn_enter_pay);
        IDBMemberPayStyleAdapter idbMemberPayStyleAdapter = new IDBMemberPayStyleAdapter(context);
        payLv.setAdapter(idbMemberPayStyleAdapter);
        this.setContentView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
        this.setCanceledOnTouchOutside(true);
        Window window = this.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.share_dialog);
        window.getDecorView().setPadding(0,0,0,0);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = context.getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        window.setAttributes(wl);

        payLv.setOnItemClickListener((parent, view1, position, id) -> payListener.pay(position));
        payBtn.setOnClickListener(v -> payListener.pay(-1));
    }
    private PayListener payListener;

    public void setPayListener(PayListener payListener) {
        this.payListener = payListener;
    }

    public interface PayListener{
        void pay(int which);
    }
}
